package wai.school.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.youth.banner.Banner;

import java.util.ArrayList;

import wai.school.R;
import wai.school.method.GlideImageLoader;
import wai.school.method.NumberedAdapter;

/**
 * Created by Finder丶畅畅 on 2017/3/12 22:47
 * QQ群481606175
 */

public class MainFragment extends Fragment {
    private int position = 0;
    ArrayList images;

    public static MainFragment newInstance(int content) {
        MainFragment fragment = new MainFragment();
        fragment.position = content;
        return fragment;
    }

    Banner banner;
    EditText main_search_et;
    LinearLayout main_top_msg_ll;//首页消息
    RecyclerView recyclerView;
    NumberedAdapter numberedAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        switch (position) {
            case 0://首页
                View view = inflater.inflate(R.layout.frag_main, container, false);
                banner = (Banner) view.findViewById(R.id.main_title_ban);
                main_search_et = (EditText) view.findViewById(R.id.main_search_et);
                main_top_msg_ll = (LinearLayout) view.findViewById(R.id.main_top_msg_ll);
                recyclerView = (RecyclerView) view.findViewById(R.id.main_tag_rl);
                images = new ArrayList<>();
                banner.setImageLoader(new GlideImageLoader());
                images.add("https://img6.bdstatic.com/img/image/smallpic/2.jpg");
                images.add("https://img6.bdstatic.com/img/image/smallpic/3.jpg");
                banner.setImages(images);
                banner.start();
                numberedAdapter = new NumberedAdapter(8);
                recyclerView.setHasFixedSize(true);
                recyclerView.setLayoutManager(new GridLayoutManager(MainActivity.admin, 4));
                recyclerView.setAdapter(numberedAdapter);
                main_search_et.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {

                    }

                    @Override
                    public void afterTextChanged(Editable s) {

                    }
                });
                main_top_msg_ll.setOnClickListener(v -> {//顶部消息点击

                });
                numberedAdapter.setOnItemClickListener((v, postion) -> {
                    MainActivity.admin.ToastShort(postion + "");
                });
                return view;
            default:
                break;

        }
        return null;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {

        super.onActivityCreated(savedInstanceState);
    }
}
